package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.system.ITripArea;
import com.gec.model.system.ITripItinerary;
import com.gec.model.system.ITripItineraryOrder;
import com.gec.model.system.ITripSightsOrder;
import com.gec.model.vo.ITripAreaQueryVo;
import com.gec.model.vo.ITripSightsOrderVo;
import com.gec.system.common.Result;
import com.gec.system.service.ITripAreaService;
import com.gec.system.service.ITripSightsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dafei
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/system/itrSightsOrder")
@Api(tags="景点订单管理")
@CrossOrigin
public class ITripSightsOrderController {
    @Autowired
    private ITripSightsOrderService iTripSightsOrderService;


    @ApiOperation("获取全部城市列表")

    @GetMapping("/findAll")
    public Result findAll()
    {
        List<ITripSightsOrder> list = this.iTripSightsOrderService.list();
        return Result.ok(list);
    }

    //    支付订单，取消订单
    @ApiOperation(value = "取消或支付出行订单")
    @PostMapping("/updateIsPaid/{id}/{isPaid}")
    public Result updateIsPaid(Long id,Integer isPaid) {

        iTripSightsOrderService.updateIsPaid(id, isPaid);
        return Result.ok();
    }
    @ApiOperation("根据id去移除一个角色")
    // 测试删除
    @DeleteMapping("/removeSightsOrder/{id}")
    public Result removeSightsOrder(@PathVariable Long id)
    {
        boolean b = this.iTripSightsOrderService.removeById(id);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
    // 分页和条件查询
    @GetMapping("/{page}/{limit}")
    public Result findSightsOrderByPageQuery(@PathVariable Long page,
                                      @PathVariable Long limit,
                                      ITripSightsOrderVo iTripSightsOrderVo)
    {
        //1.创建分页对象
        IPage<ITripSightsOrder> p1 = new Page<>(page,limit);
        //2.调用方法
        p1 =    this.iTripSightsOrderService.selectPage(p1,iTripSightsOrderVo);
        //3.返回
        return Result.ok(p1);
    }

//    用户取消订单


    // 修改

    @GetMapping("/findSightsOrderById/{id}")
    public Result findSightsOrderById(@PathVariable Long id)
    {
        ITripSightsOrder iTripSightsOrder = this.iTripSightsOrderService.getById(id);
        return Result.ok(iTripSightsOrder);
    }



    // 实现修改
    @PostMapping("/updateSightsOrder")
    public Result updateSightsOrder(@RequestBody ITripSightsOrder iTripSightsOrder)
    {
        boolean b = this.iTripSightsOrderService.updateById(iTripSightsOrder);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
    // 批量删除
    @DeleteMapping("/removeSightsOrderByIds")
    public Result removeSightsOrderByIds(@RequestBody List<Long> ids)
    {
        boolean b = this.iTripSightsOrderService.removeByIds(ids);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
}

